package com.wlcj.www.web.data;

import java.util.List;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;

import com.wlcj.constant.Global;
import com.wlcj.www.model.data.PlatformAttention;
import com.wlcj.www.service.AttentionService;
import com.wlcj.www.util.DataUtil;
import com.wlcj.www.web.BaseAction;

public class AttentionAction extends BaseAction {
	private AttentionService dataService = s(AttentionService.class);
	public void index() {
		/*if(getSessionAttr(Global.SESSION_LOGIN_KEY)==null){
			renderJsp(Global.REDIRECT_URL);
		}else{
			String provinceId = getPara("provinceId");
			String timeStr = getPara("timeStr");
			if(StringUtils.isBlank(timeStr)){
				timeStr = DataUtil.createTypeStr(DataStoreType.YESTERDAY.getCode());
			}
			String uid = String.valueOf(getUserId());
			List<PlatformAttention> dataList = dataService.getDataList(timeStr, "volume desc", provinceId,uid);
			List<Province> provinceList = dataService.getAllProvinces();
			setAttr("dataList", dataList);
			setAttr("provinceList", provinceList);
			renderJsp("/WEB-INF/jsp/data/my_concern.jsp");
		}*/
	}
	public void concernTable() {
		if(getSessionAttr(Global.SESSION_LOGIN_KEY)==null){
			renderJsp(Global.REDIRECT_URL);
		}else{
			String provinceId = getPara("provinceId");
			String timeStr = getPara("timeStr");//2014-4-24
			List<PlatformAttention> dataList = null;
			String[] times = new String[2];
			String uid = String.valueOf(getUserId());
			if(StringUtils.isNotBlank(timeStr)){
				times = timeStr.split("/");
			}else{
				timeStr = DataUtil.createTypeStr(getParaToInt("timeType"));//7日，30日，
			}
			
			System.err.println(timeStr);
			String orderby = getPara("orderby");
			String column = getPara("column");
			dataList = dataService.getDataList(timeStr, column+" "+orderby, provinceId,uid);
			if(CollectionUtils.isEmpty(dataList)){
				String[] strs = timeStr.split("/");
				if(times[0]!=null&&times[1]!=null){
					dataList = dataService.getDataList(times, column+" "+orderby, provinceId,uid);
				}else{
					dataList = dataService.getDataList(strs, column+" "+orderby, provinceId,uid);
				}
			}
			setAttr("dataList", dataList);
			renderJsp("/WEB-INF/jsp/data/concernTable.jsp");
		}
	}
	public void dellAttention(){
		if(getSessionAttr(Global.SESSION_LOGIN_KEY)==null){
			renderJsp(Global.REDIRECT_URL);
		}else{
			try {
				int uid = getUserId();
				int pid = getParaToInt("pid");
				dataService.dellUserAttentionPlatform(uid, pid);
				success("ok");
			} catch (Exception e) {
				e.printStackTrace();
				fail("取消关注失败！！");
			}
		}
	}
}
